{% extends "app/base_site.html" %}

{% block title %} 标注任务管理 {% endblock title %}

{% block stylesheets %}
  {{ block.super }}

{% endblock stylesheets %}

{% block content %}

  <div class="right_col" role="main">
    <div class="">
      <div class="row">
          <div class="col-md-12 col-sm-12 col-xs-12">
            <div class="x_panel">
              <div class="x_title">
               <h2>标注任务管理
                    <span id="top_loading" ><img class="top_loading_img" src="/static/images/load.gif" alt="loading">加载中</span>
                    <span id="top_msg">{{top_msg}}</span>

                 <button onclick="f_sync()" class="btn btn-default btn-sm"> 全量同步进度</button>

                        </h2>

                <div class="clearfix"></div>
              </div>
              <div class="x_content">
                <!--<p><code>说明</code> 系统支持的行为算法</p>-->
                <div class="table-responsive">
                  <table class="table table-bordered">
                    <thead>
                      <tr class="headings">
                        <th class="column-title">ID</th>
                        <th class="column-title">编号</th>
                            <th class="column-title">名称</th>
                        <th class="column-title">创建用户</th>

                        <th class="column-title">任务类型</th>
                        <th class="column-title">标注进度</th>
                        <th class="column-title">更新时间</th>
                          <th class="column-title no-link last"><span class="nobr">操作</span></th>
                      </tr>
                    </thead>

                    <tbody>
                    {%  for d  in data %}
                      <tr class="even pointer">
                        <td>{{ d.id }}<!--{{forloop.counter}}--></td>
                        <td>{{ d.code }}</td>
                           <td>{{ d.name }}</td>
                        <td>{{ d.username }}</td>

                        <td>{% if d.task_type == 1 %} 视频任务 {% endif %}</td>
                          <td>{{ d.sample_annotation_count }} / {{ d.sample_count }}</td>
                          <td>{{ d.last_update_time }}</td>
                          <td>
                              <div class="btn-group">
                              <button onclick="f_edit('{{ d.code }}')" class="btn btn-sm btn-default" type="button"  data-placement="top" data-toggle="tooltip" data-original-title="编辑任务"><i class="fa fa-edit"></i></button>
                              <button onclick="f_sample('{{ d.code }}')" class="btn btn-sm btn-default" type="button" data-placement="top" data-toggle="tooltip" data-original-title="开始标注"><i class="fa fa-tags"></i></button>
                              <button onclick="f_labeltkTrain('{{ d.code }}')" class="btn btn-sm btn-default" type="button" data-placement="top" data-toggle="tooltip" data-original-title="开始训练"><i class="fa fa-train"></i></button>
                              <button onclick="f_del('{{ d.code }}')" class="btn btn-sm btn-default" type="button" data-placement="top" data-toggle="tooltip" data-original-title="删除任务"><i class="fa fa-remove"></i></button>
                            </div>
                        </td>
                      </tr>
                    {% endfor %}

                    </tbody>
                  </table>
                </div>
              </div>

            </div>
          </div>
      </div>

      <div class="row">
          <div class="col-md-12 col-sm-12 col-xs-12">
            <ul class="pagination">
                <li>
                    <span style="margin-right:10px;color:#000;">共<span>{{ pageData.page_num}}</span>页 / <span>{{pageData.count}}</span >条</span>
                </li>

                {%  for d  in pageData.pageLabels%}
                  {% if d.cur == 1 %}
                    <li class="paginate_button active"><a href="#"  >{{ d.name }}</a></li>
                  {% else %}
                    <li class="paginate_button "><a href="/labelTask/index?p={{d.page}}&ps={{pageData.page_size}}" >{{ d.name }}</a></li>
                  {% endif %}
                {% endfor %}

              <!--
              <li class="paginate_button previous" ><a href="#" data-dt-idx="0" >上一页</a></li>
              <li class="paginate_button active"><a href="#" data-dt-idx="1" >1</a></li>

              <li class="paginate_button "><a href="#" data-dt-idx="2">2</a></li>
              <li class="paginate_button "><a href="#" data-dt-idx="3">3</a></li>
              <li class="paginate_button "><a href="#" data-dt-idx="4">4</a></li>
              <li class="paginate_button "><a href="#" data-dt-idx="5" >5</a></li>
              <li class="paginate_button "><a href="#" data-dt-idx="6" >6</a></li>
              <li class="paginate_button next"><a href="#" data-dt-idx="7" >下一页</a></li>
              -->
            </ul>

          </div>
       </div>


    </div>
  </div>

{% endblock content %}

{% block javascripts %}
  {{ block.super }}
<script>
    let ele_top_loading = $("#top_loading");
    let ele_top_msg= $("#top_msg");
    function f_sample(task_code) {
        let url = "/labelTask/sample?task_code="+task_code;
        window.location.href = url;
    }

     function f_labeltkTrain(task_code) {
        window.location.href = "/labeltkTrain/add?task_code="+task_code;

     }
    function f_sync() {
        ele_top_loading.show();
        $.ajax({
               url: '/labelTask/sync',
               type: "get",
               async: true,
               data: {},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myAlert("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                   ele_top_loading.hide();
                   if(1000 === res.code){
                        window.location.reload();
                   }else{
                        myAlert(res.msg,"error");
                   }
               }
            });
    }
    function f_edit(code) {
        let url = "/labelTask/edit?code="+code;
        window.location.href = url;
    }
    function f_del(code){
        ele_top_loading.show();
        $.ajax({
               url: '/labelTask/postDel',
               type: "post",
               async: true,
               data: {"code":code},
               dataType: "json",
               timeout: 0,
               error: function () {
                   ele_top_loading.hide();
                   myAlert("网络异常，请确定网络正常！","error");
               },
               success: function (res) {
                   ele_top_loading.hide();
                   if(1000 === res.code){
                        window.location.reload();
                   }else{
                        myAlert(res.msg,"error");
                   }
               }
            });

    }
</script>

{% endblock javascripts %}

